<?php
class OrderRoom extends OrderRoomPeer
{
	function OrderRoom()
	{
		parent::OrderRoomPeer();
	}
	
	
	public static function retriveByOrderIdAndRoomId($order_id, $room_id)
	{
		$db = new Database();
		$query = "SELECT id FROM order_room WHERE order_id = ".$order_id." AND room_id = ".$room_id;
		$result = $db->query($query);
		$id = $db->result;
		$id = mysql_fetch_row($id);
		if (isset($id[0])) {
			$id = $id[0];
			$order_room = new OrderRoom();
			$order_room->select($id);
			return $order_room;
		}
		return null;
	}
	
	
	public static function getAllRoomsByOrder($order_id)
	{
		$db = new Database();
		$query = "SELECT room_id FROM order_room WHERE order_id = ".$order_id;
		$db->query($query);
		$ids = $db->fetch_array($db->result);
		$rooms = array();
		foreach ($ids as $id)
			if ($id['id']) {
				$room = new Room();
				$room->select($id['id']);
				$rooms[] = $room;
			}
		return $rooms;
	}
}
?>